#include<bits/stdc++.h>
using namespace std;
int t,n,a[200005],c[200005],s;
void b(){
    int h=0,l=0,u=0;
    for(int i=1;i<=n;i++){
        if(c[i]==1){
            if(h==a[i]){
                u+=a[i];
            }h=a[i];
        }if(c[i]==2){
            if(l==a[i]){
                u+=a[i];
            }l=a[i];
        }
    }s=max(s,u);
    return;
}
void dfs(int w){
    if(w==n+1){
        b();
        return;
    }c[w]=1;
    dfs(w+1);
    c[w]=2;
    dfs(w+1);
    return;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin >> t;
    for(int y=1;y<=t;y++){
        memset(c,0,sizeof(c));
        s=0;
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }dfs(1);
        cout << s << endl;
    }
    return 0;
}
